<?php
/* 
 * ebiz front
 * 
 * apply gift log Model
 * 
 * @author allen
 * 
 */
require_once '../app/core/models/BaseDao.php';
require_once '../app/core/db/DBUtil.class.php';

class ApplyGiftLogDao extends BaseDao 
{
	
    private $tableName = "apply_gift_logs";   
    
    public function __construct($dbUtil){ 
        parent::__construct($dbUtil);
        $this->_name = $this->tableName;        
    }
    
    public function saveLogs($param){     //this is register
		$sql = "insert into $this->tableName 
		(apply_type, user_id, points, current_exhaust_points, current_ac_points, gift_id, status, 
		delivery_name, delivery_phone1, delivery_phone2, delivery_address1, delivery_address2, delivery_address3, 
		delivery_detail_address, delivery_email, modified, created) 
		values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,now(),now())";
        return $this->dbUtil->ExecuteQuery($sql, $param);
    }
    
    public function saveCouponLogs($param){     //this is register
		$sql = "insert into $this->tableName 
		(apply_type, user_id, points, current_exhaust_points, current_ac_points, status, promotion_id, coupon_code, modified, created) 
		values (?,?,?,?,?,?,?,?,now(),now())";
        return $this->dbUtil->ExecuteQuery($sql, $param);
    }
    
    public function getApplyGiftInfo($int_page, $int_limit, $userId){
        $param = array($userId);
        $sql = "select * from $this->tableName where user_id=? and is_delete = 0 order by created desc limit $int_page, $int_limit";
        return $this->dbUtil->SelectData($sql,$param);
    }
    
    public function getAllNumber($userId){
    	$param = array($userId);
        $sql = "select count(*) as allNum from $this->tableName where user_id=? and is_delete = 0 ";
        return $this->dbUtil->SelectData($sql,$param);
    }
    
    public function getApplyLogById($id){
         $param = array($id);
         $sql = "select * from $this->tableName where is_delete = 0 and id = ?";
         return $this->dbUtil->SelectData($sql,$param);
    }
    
    public function updateApplyGiftLog($data,$couponCode,$userId){
        $where = " apply_type = 1 and user_id = {$userId} and  coupon_code = '{$couponCode}' and is_delete = 0 ";
        return $this->update($data,$where);
    }
    
}



